package com.xian.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xian.common.annotation.Log;
import com.xian.common.core.controller.BaseController;
import com.xian.common.core.domain.AjaxResult;
import com.xian.common.enums.BusinessType;
import com.xian.manage.domain.Search;
import com.xian.manage.service.ISearchService;
import com.xian.common.utils.poi.ExcelUtil;
import com.xian.common.core.page.TableDataInfo;

/**
 * 新闻信息Controller
 * 
 * @author Hanys
 * @date 2025-04-08
 */
@RestController
@RequestMapping("/manage/search")
public class SearchController extends BaseController
{
    @Autowired
    private ISearchService searchService;

    /**
     * 查询新闻信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:search:list')")
    @GetMapping("/list")
    public TableDataInfo list(Search search)
    {
        startPage();
        List<Search> list = searchService.selectSearchList(search);
        return getDataTable(list);
    }

    /**
     * 导出新闻信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:search:export')")
    @Log(title = "新闻信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Search search)
    {
        List<Search> list = searchService.selectSearchList(search);
        ExcelUtil<Search> util = new ExcelUtil<Search>(Search.class);
        util.exportExcel(response, list, "新闻信息数据");
    }

    /**
     * 获取新闻信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:search:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(searchService.selectSearchById(id));
    }

    /**
     * 新增新闻信息
     */
    @PreAuthorize("@ss.hasPermi('manage:search:add')")
    @Log(title = "新闻信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Search search)
    {
        return toAjax(searchService.insertSearch(search));
    }

    /**
     * 修改新闻信息
     */
    @PreAuthorize("@ss.hasPermi('manage:search:edit')")
    @Log(title = "新闻信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Search search)
    {
        return toAjax(searchService.updateSearch(search));
    }

    /**
     * 删除新闻信息
     */
    @PreAuthorize("@ss.hasPermi('manage:search:remove')")
    @Log(title = "新闻信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(searchService.deleteSearchByIds(ids));
    }
}
